collapse_faithful_seed = {
	every_ruler = {
			set_character_faith = global_var:magister_character.faith 
		every_courtier_or_guest = {
			set_character_faith = global_var:magister_character.faith 
		}

		every_held_title = {
			title_tier = county
			set_county_faith = global_var:magister_character.faith
			title_province = { save_scope_as = pool_province }
			every_pool_character = {
				limit = { NOT = { is_in_list = pool_characters } }
				province = scope:pool_province
				add_to_list = pool_characters
			}
		}
	}

	every_in_list = {
		list = pool_characters
		set_character_faith = global_var:magister_character.faith 
	}
}
subdue_hermilia_landless_effect = {
		
		scope:hermilia ={
			if = {
				limit = { scope:hermilia = {has_government = landless_adventurer_government}}
				destroy_laamp_effect = { ADVENTURER = scope:hermilia }
			}
			subdue_hermilia_effect = yes
		}
		ROOT = {
			add_courtier = scope:hermilia
		}
}
subdue_hermilia_vassal_effect = {
	scope:hermilia ={
			subdue_hermilia_effect = yes
		}
}
subdue_hermilia_prisoner_effect = {
	scope:hermilia = {
	 release_from_prison = yes
	 }
	 if = {
		limit = {
			OR ={
						has_government = landless_adventurer_government
						is_courtier = yes
						is_foreign_court_or_pool_guest = yes
				}
			}
			subdue_hermilia_landless_effect = yes
		}
		else_if = {
			limit = {
				NOT = {
					any_liege_or_above = {
								this = root
					}
				}
				}
				subude_hermilia_handle_vassalization = yes
				subdue_hermilia_effect = yes
			}

		else = {
			subdue_hermilia_effect = yes
		}
	
}
subude_hermilia_handle_vassalization = {

		create_title_and_vassal_change = {
			type = swear_fealty
			save_scope_as = change
			add_claim_on_loss = no
		}
		
		if = {
			limit = {
				scope:hermilia.primary_title.tier < root.primary_title.tier
			}
			scope:hermilia = {
				change_liege = {
					liege = root
					change = scope:change
				}
			}
		}
		else = {
			scope:hermilia = {
				every_held_title = {
					if = {
						limit = {
							tier = scope:hermilia.primary_title.tier
						}
						change_title_holder = {
							holder = root
							change = scope:change
						}
					}
					else_if = {
						limit = {
							OR = {
								NOT = { exists = scope:secondary_title }
								tier > scope:secondary_title.tier
							}
						}
						save_temporary_scope_as = secondary_title
					}
				}
			}
			
			scope:hermilia = {
				if = {
					limit = {
						exists = scope:secondary_title
					}
					every_vassal = {
						limit = {
							primary_title.tier >= scope:secondary_title.tier
							NOT = {
								primary_title.tier = tier_barony
							}
						}
						change_liege = {
							liege = root
							change = scope:change
						}
					}
				}
			}
			
			scope:hermilia = {
				change_liege = {
					liege = root
					change = scope:change
				}
			}
		}
		
		resolve_title_and_vassal_change = scope:change
}
subdue_hermilia_effect = {
	collapse_faithful_seed = yes
	scope:hermilia = {
		every_spouse = {
					show_as_tooltip = {
						if = {   
							limit = { is_female = yes }
							divorce = scope:hermilia 
							marry = ROOT
						}
				
					}
			}
		every_concubine = {
			show_as_tooltip = {
						if = {   
							limit = { is_female = yes }
							remove_concubine = scope:hermilia 
							marry = ROOT
						}
				
					}
		}
		if = {
			limit = { 
					NOT = { has_trait = futa_divine_balls }
			}
			add_trait_force_tooltip = futa_divine_balls
			}
		if = {
				limit = { 
						NOT = { has_trait = futa_divine_ovaries }
					} 
				add_trait_force_tooltip = futa_divine_ovaries
		}
		
	regula_make_paelex_hermilia_effect = yes
	}
	
	ROOT = {
		if = {
			limit = {
				is_female = yes
			}
				if = {
					limit = { 
							NOT = { has_trait = futa_divine_balls }
					}
					add_trait_force_tooltip = futa_divine_balls
					}
				if = {
						limit = { 
								NOT = { has_trait = futa_divine_ovaries }
							} 
						add_trait_force_tooltip = futa_divine_ovaries
				}
		}
		}
}
regula_make_paelex_hermilia_effect = {

	# Iterate Domitans Tribunal counter
	change_global_variable = {
		name = regula_domitans_tally
		add = 1
	}

	scope:hermilia= {
		# Remove Mulsa trait
		remove_trait = mulsa
		remove_trait = tropaeum
		
		# Sex to bisexual
		set_sexuality = bisexual

		# Create memory of being dominated by the ROOT
		create_character_memory = {
			type = regula_memory_domitans_tribunal
			participants = { magister = global_var:magister_character }
		}

		# Domitans pregnancy trigger
		hidden_effect = {
			if = {
				limit = { is_pregnant = yes }
				trigger_event = regula_paelex_event.1040
			}
		}

		# Break up with male lovers (not including Magister)
		# This also includes soulmates
		every_relation = {
			type = lover
			limit = {
				AND = {
					NOT = { this = ROOT }
					is_male = yes	# Female lovers are ok!
				}
			}
			lover_breakup_effect = {
				BREAKER = scope:hermilia
				LOVER = this
			}
		}

	
		Break any betrothals which may exist (without additional opinion penalties).
		# Its ok to break Magister betrothal because you marry them after
		if = {
			limit = { exists = betrothed }
			betrothed = { trigger_event = marriage_interaction.0041 }
			break_betrothal = betrothed
		}
	}

	root= {
		# Marry scope:hermilia
		marry = scope:hermilia

		# Run Domitans event, which is really just a Mutare Corpus event with custom text (and a specific trait)
		trigger_event = { on_action = regula_domitans_event_selector }

		# Magister XP grants for Domitans Tribunal / Make Paelex
		regula_grant_magister_xp_effect = { TRACK = domination AMOUNT = minor }
		regula_grant_magister_xp_effect = { TRACK = knowledge AMOUNT = tiny }
	}
}

# Add the correct Paelex trait, depending on ROOT relation to scope:hermilia
regula_add_paelex_trait_effect = {

	# Domina (scope:hermilia is Primary Spouse)
	if = {
		limit = { ROOT.primary_spouse = scope:hermilia }
		scope:hermilia = {
			add_trait_force_tooltip = domina
		}
	}
	# Domina (ROOT is not married yet)
	else_if = {
		limit = {
			ROOT = {
				is_married = no
			}
		}
		scope:hermilia = {
			add_trait_force_tooltip = domina
		}
	}
	# Family Paelex (scope:hermilia is in ROOT dynasty)
	else_if = {
		limit = { 
			ROOT.dynasty = {
				any_dynasty_member = {
					this = scope:hermilia
				}
			}
		}
		scope:hermilia = {
			add_trait_force_tooltip = familia_paelex
		}
	}
	# Normal Paelex
	else = {
		scope:hermilia = {
			add_trait_force_tooltip = paelex
		}
	}
}